// Dustin Escoffery
// Copyright 2010
#include "hook_storm.h"
#include "hook_window.h"
#include "hook_ddraw.h"

static WNDPROC lpfnDlgProc = NULL;

// storm (bnet) windows
// WS_POPUP, WS_CHILD
HWND WINAPI MyCreateWindowEx2(DWORD dwExStyle, LPCTSTR lpClassName,
   LPCTSTR lpWindowName, DWORD dwStyle, int x, int y, int nWidth,
   int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance,
   LPVOID lpParam)
{
   // Force default size
   if (hWndParent == GetMainWindow())
      SendMessage(GetMainWindow(), WM_SYSCOMMAND, 100, 0);
   // Translate
   if (dwStyle & WS_POPUP)
   {
      POINT p = {x, y};
      ClientToScreen(hWndParent, &p);
      x = p.x;
      y = p.y;
      dwExStyle |= WS_EX_LAYERED;
   }
   HWND hWnd = CreateWindowEx(dwExStyle, lpClassName, lpWindowName, dwStyle,
      x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
   if (dwStyle & WS_POPUP) SetLayeredWindowAttributes(hWnd, 0, 1, LWA_ALPHA);
   return hWnd;
}

// prepare storm (bnet) windows for moved position
BOOL WINAPI MyClientToScreen(HWND hWnd, LPPOINT lpPoint)
{
   BOOL ret = ClientToScreen(hWnd, lpPoint);
   POINT p = {0, 0};
   ClientToScreen(GetMainWindow(), &p);
   lpPoint->x -= p.x;
   lpPoint->y -= p.y;
   return ret;
}

LRESULT CALLBACK WINAPI MyDialogProc(HWND hWnd, UINT uMsg,
   WPARAM wParam, LPARAM lParam)
{
   switch (uMsg)
   {
      // Show Cursor
      case WM_MOUSEMOVE:
         while(ShowCursor(true) < 0);
         break;
   }
   return CallWindowProc(lpfnDlgProc, hWnd, uMsg, wParam, lParam);
}

// storm (bnet) dialog boxes
// SDlgDialog, SDlgStatic
ATOM WINAPI MyRegisterClass(const WNDCLASS *lpWndClass)
{
   if (!strcmp(lpWndClass->lpszClassName, "SDlgDialog"))
   {
      WNDCLASS* lpWC = (WNDCLASS*)lpWndClass;
      lpfnDlgProc = lpWC->lpfnWndProc;
      lpWC->lpfnWndProc = (WNDPROC)MyDialogProc;
   }
   return RegisterClass(lpWndClass);
}
